package com.lujieni.springbootrocketmq.controller;


import com.lujieni.springbootrocketmq.dto.OrderDTO;
import com.lujieni.springbootrocketmq.service.MessageProducer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/mq")
public class MQTestController {

    @Autowired
    private MessageProducer messageProducer;

    @PostMapping("/sendOrder")
    public String sendMessage(@RequestBody OrderDTO orderDTO) {
        messageProducer.sendMessage("test-topic", "lujieni", orderDTO);
        return "ok";
    }

    /**
     * 消息的顺序发送
     * @return
     */
    @PostMapping("/sendOrderOrderly")
    public String sendMessageOrder(@RequestBody OrderDTO orderDTO) {
        messageProducer.sendMessageOrder("test-topic", "lujieni", orderDTO);
        return "ok";
    }

    /**
     * 消息的延迟发送
     * @return
     */
    @PostMapping("/sendOrderDelay")
    public String sendMessageDelay(@RequestBody OrderDTO orderDTO) {
        messageProducer.sendMessageDelay("test-topic", "lujieni", orderDTO);
        return "ok";
    }

    /**
     * 消息的延迟发送
     * @return
     */
    @PostMapping("/sendOrderTransaction")
    public String sendMessageTransaction(@RequestBody OrderDTO orderDTO) {
        messageProducer.sendMessageTransaction("test-topic", "lujieni", orderDTO);
        return "ok";
    }
}